package com.zh.netty.http;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.ServerChannel;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpServerCodec;

/**
 * @Description:
 * @ClassName TestServerInitalzer
 * @date: 2021.02.11 16:49
 * @Author: zhanghang
 */
public class TestServerInitalzer extends ChannelInitializer<SocketChannel> {
    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        // 向管道加入处理器

        // 得到管道
        ChannelPipeline pipeline = ch.pipeline();

        // 加入一个netty 提供的httpServerCodec
        // HttpServerCodec 说明
        // 1. httpServerCodec是Netty 提供的处理http 的编码解码器
        pipeline.addLast("myHttpServerCodec",new HttpServerCodec());
        // 2. 增加一个自定义的handler
        pipeline.addLast("myTestHttpServerHandler",new TestHttpServerHandler());
    }
}
